let mongoose = require('./db')
var Schema = mongoose.Schema;
//商品分类表
let TypesSchema = new mongoose.Schema({
    //类型名称
    type_name: String
})
//视频表
let VideosSchema = new mongoose.Schema({
    //用户id
    uid: {
        type: mongoose.Types.ObjectId,
        ref: 'Users'
    },
    //封面地址
    cover: { type: String, default: '' },
    //视频地址
    video: String,
    //合集名称
    collections: { type: String, default: '' },
    //点赞者
    likes: {
        type: [mongoose.Types.ObjectId],
        ref: 'Users',
        default: []
    },
    //类型
    types: {
        type: [mongoose.Types.ObjectId],
        ref: 'Types',
        default: []
    },
    title: String
})
//用户表
let UserSchema = new mongoose.Schema({
    //用户名/账号
    username: String,
    //密码
    password: String,
    //昵称
    name: String,
    //头像 有默认值
    avatar: {
        type: String,
        default: 'https://tse2-mm.cn.bing.net/th/id/OIP-C.fyEXIh3DvxKLlWHXYEbmOQAAAA?w=200&h=200&c=7&r=0&o=5&dpr=1.3&pid=1.7'
    },
    //电话
    phone: String,
    //关注
    concern: {
        type: [mongoose.Types.ObjectId],
        ref: 'Users',
        default: []
    },
    //观看历史
    watch_history: {
        type: [mongoose.Types.ObjectId],
        ref: 'Videos',
        default: []
    },
    //人脸
    face: String,
    headshow: { type: Number },
    account: { type: String },
})

//聊天记录
var privateSchema = new Schema({
    selfaccount: { type: String },
    selfname: { type: String },
    othername: { type: String },
    otheraccount: { type: String },
    chathistory: { type: Array }
})
//聊天室
var groupScheme = new Schema({
    time: { type: String },
    username: { type: String },
    account: { type: String },
    content: { type: String }
})


let UsersModel = mongoose.model('Users', UserSchema, 'Users')
let VideosModel = mongoose.model('Videos', VideosSchema, 'Videos')
let TypesModel = mongoose.model('Types', TypesSchema, 'Types')

let privateHistory = mongoose.model('privatehistories', privateSchema)
let groupHistory = mongoose.model('grouphistories', groupScheme)
module.exports = {
    UsersModel,
    VideosModel,
    TypesModel,
    privateHistory,
    groupHistory
}